<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>智银华通-图文消息列表</title>
	<link rel="shortcut icon" type="image/ico" href="${basePath}/favicon.ico"/>
	<link rel="stylesheet" type="text/css" href="${basePath}/css/style-1.css" />
	<link rel="stylesheet" type="text/css" href="${basePath}/css/style_2_common.css" />
	<link rel="stylesheet" type="text/css" href="${basePath}/css/more_img.css" />
	<script type="text/javascript" src="${basePath}/js/jquery-1.8.3.min.js"></script>
	<link rel="stylesheet" type="text/css" href="${basePath}/js/layer/skin/layer.css" />
    <script type="text/javascript" src="${basePath}/js/layer/layer.m.js"></script>
    <script type="text/javascript" src="${basePath}/js/layer/extend/layer.ext.js"></script>
    <style rel="stylesheet">
    	#cron_expression_panal{
    		display:none;
    		padding-top:10px;
    	}
    	#cron_expression_panal input{
    		border:solid 1px #EAEAEA;
    		width:30px;
    	}
    </style>
</head>
<body id="nv_member" class="pg_CURMODULE">
<#assign current='menu_mass'>
	<div id="wp" class="wp">
		<#include "/include/header.html"/>
		<!--中间内容-->
		<div class="contentmanage">
			<div class="developer">
				<div class="tableContent">
					<#include "/include/left.html"/>
					<#include "/include/wxtop.html"/>
					<div class="content">
						<div class="cLineB">
							<h4 style="font-size:16px;">
								消息群发<span class="FAQ"></span>
							</h4>
						</div>
						<div class="cLine">
							<div class="pageNavigator left">
								<a href="${basePath}/admin/mass/add" title="新增语音回复" class="btnGrayS vm bigbtn"><img width="16" src="${basePath}/images/add.png" class="vm">新增群发消息</a>
							</div>
							<div class="clr"></div>
						</div>
						<div style="padding-left:10px;" class="ftip">群发状态不是实时的，有一定延迟，请耐心等待结果；另外，历史数据可能没有结果；预览接口调用限制为每日100次。</div>
						<div class="msgWrap form">
							<div class="bdrcontent">
								<div id="div_ptype">
									<table class="ListProduct Shallow_border_color" border="0"
								cellSpacing="0" cellPadding="0" width="100%">
										<thead>
											<tr>
												<th style="width: 80px;">标题</th>
												<th style="width: 60px;">群发类型</th>
												<th style="width: 60px;">消息类型</th>
												<th style="width: 60px;">消息标题</th>
												<th style="width: 80px;">发送时间</th>
												<th style="width: 100px;">群发结果</th>
												<th style="width: 60px;">群发状态</th>
												<th style="width: 160px;">操作</th>
											</tr>
										</thead>
										<tbody>
											<#if page?exists>
											<#list page.recordList as bean>
												<tr>
													<td title="${bean.title?default('')}">${bean.title?default('')}</td>
													<td>
														标签群发
													</td>
													<#assign content=bean.content?eval />
													<td><#if content.msgType==1>文本<#elseif content.msgType==2>单图文<#elseif content.msgType==3>多图文<#elseif content.msgType==4>音频</#if></td>
													<td>${content.msgTitle?default('暂无')}</td>
													<td>
														<#if bean.sendTime?exists>${bean.sendTime?date}<#else>未发送</#if>
													</td>
													<td style="text-align:left;">
														发送粉丝数：${bean.totalCount?default('未知')}</br>
														发送成功数：${bean.sentCount?default('未知')}</br>
														发送失败数：${bean.errorCount?default('未知')}
													</td>
													<td><#if (bean.sendStatus?exists) && (bean.sendStatus==1)>已发送<#else>未发送</#if></td>
													<td class="norightborder" style="text-align:left;">
														<a href="javascript:void(0);" onclick="sendNow('${bean.id}');">发送</a>
														<#if !(bean.sendTime?exists)>
														<#if bean.isInterval?exists>
														<a href="javascript:void(0);">已定时</a>
														<#else>
														<a href="javascript:void(0);" onclick="sendSomeTime('${bean.id}');">定时发送</a>
														</#if>
														</#if>
														<a href="javascript:void(0);" onclick="delItem('${bean.id}');">删除</a>
														<a href="javascript:void(0);" onclick="preview('${bean.id}');" title="预览每日限定100次，请谨慎使用!">预览</a>
														<#if !((bean.sendStatus?exists) && (bean.sendStatus==1))>
														<a href="javascript:void(0);" onclick="syn('${bean.id}');" title="如果修改了图文，那么请使用此功能">同步素材</a>
														</#if>
													</td>
												</tr>
											</#list>
											</#if>
										</tbody>
									</table>
								</div>
							</div>
							<#assign formUrl="${basePath}/admin/mass/list?">
							<#include "include/pagination.html"/>
						</div>
					</div>
					<div class="clr"></div>
				</div>
			</div>
		</div>
		<!--底部-->
		<div id="cron_expression_panal">
			&nbsp;
			<input name="year" type="text" readonly placeholder="年"/>-
			<input name="month" type="text"  placeholder="月"/>-
			<input name="day"  type="text" placeholder="日"/>&nbsp;&nbsp;
			<input name="hour" type="text"  placeholder="时" /> :
			<input name="minute" type="text"  placeholder="分"/> :
			<input name="second"  type="text" placeholder="秒"/>
		</div>
	</div>
	<#include "/include/footer.html"/>
	
	<script type="text/javascript">
		function delItem(item){
			layer.confirm("确定要删除吗？",{icon:4},function(index){
				layer.close(index);
				var url = "${basePath}/admin/mass/del";
				var $form=$("<form>" );
				$form.attr( "style","display:none" ).attr( "target","").attr( "method","post" ).attr( "action",url);
				$form.append("<input name='flag' type='hidden' value='"+item+"'/>");
				$("body").append($form);
				$form.submit();
			},function(index){
				layer.close(index);
			});
		}
		function sendNow(itemNo){
			var layerIndex = layer.msg('处理中，请稍后...', {icon: 16,shade: [0.5, '#393D49'],time:0});
			$.post("${basePath}/admin/mass/msg",{"id":itemNo},function(data){
				layer.close(layerIndex);
				if(data.success==true){
					layer.msg("图文已发送");
				}else{
					if(data.errorMsg){
						layer.msg(data.errorMsg);
					}
				}
				var $form=$("<form>" );
	  			$form.attr( "style","display:none" );
	  			$form.attr( "target","");
	     		$form.attr( "method","post" );
	            $form.attr( "action","${basePath}/admin/mass/list?currentPage=${currentPage}");
				$("body").append($form);
				$form.submit();
			});
		}
		
		function sendSomeTime(itemNo){
			var $cron = $("#cron_expression_panal");
			$cron.find("input[name='year']").val(new Date().getFullYear());
			var $layer;
			window.layerIndex = layer.open({
				type: 1,
			    scrollbar: false,
			    move:false,
			    success:function(layero, index){
			    	$layer = $(layero);
			    },
			    btn:["确定","取消"],
			    yes:function(index){
			    	var $month = $layer.find("input[name='month']");
			    	var $day = $layer.find("input[name='day']");
			    	var $hour = $layer.find("input[name='hour']");
			    	if($month.val()==""){
			    		$month.focus();
			    		layer.tips("必填", $month.get(0));
			    		return false;
			    	}
			    	if($day.val()==""){
			    		$day.focus();
			    		layer.tips("必填", $day.get(0));
			    		return false;
			    	}
			    	if($hour.val()==""){
			    		$hour.focus();
			    		layer.tips("必填", $hour.get(0));
			    		return false;
			    	}
			    	var json = {};
			    	json.id = itemNo;
			    	var $input = $layer.find("input");
			    	var size = $input.length;
			    	for(var i=0;i<size;i++){
			    		var $in = $input.eq(i);
			    		json[$in.attr("name")] = $in.val();
			    	}
			    	$.post("${basePath}/admin/mass/task", json, function(data){
				    	layer.close(index);
				    	layer.alert(data.message);	
				    	window.location.href = window.location;	    		
			    	},"json");
			    },
			    cancel:function(index){
			    	layer.close(index);
			    },
			    area: ['250px', '120px'],
			    fix: true,
			    title: '设置发送时间',
			    content: $cron
			});
		}
		
		//预览
		function preview(itemNo){
			layer.prompt({
			    title: '请输入微信号以实现预览功能',
			    formType: 0
			}, function(text,index){
			    if(""!=text){
			    	var loadingIndex = layer.msg('加载中', {icon: 16,time:0,shade: [0.5, '#393D49']});
			    	$.post("${basePath}/admin/mass/preview",{id:itemNo, type:0, code:text},function(data){
			    		layer.close(loadingIndex);
			    		if(data.state==200){
			    			layer.msg('预览成功，请注意接收微信消息！', {icon: 16,shade: [0.5, '#393D49']});
			    		}else{
			    			if(""==data.msg){
			    				data.msg="预览失败";
			    			}
			    			layer.alert(data.msg);
			    		}
			    	},"json");
			    }else{
			    	layer.alert("微信号不能为空！");
			    }
			    layer.close(index);
			});
		}
		
		//同步
		function syn(itemNo){
			var loadingIndex = layer.msg('请稍候', {icon: 16,time:0,shade: [0.5, '#393D49']});
			$.post("${basePath}/admin/mass/syn",{id:itemNo},function(data){
	    		layer.close(loadingIndex);
	    		if(data.state==200){
	    			layer.msg('同步成功', {icon: 16,shade: [0.5, '#393D49']});
	    		}else{
	    			if(""==data.msg){
	    				data.msg="同步失败";
	    			}
	    			layer.alert(data.msg);
	    		}
	    		layer.close(loadingIndex);
	    	},"json");
		}
	</script>
</body>
</html>